package com.work.demo.file;

import java.io.FileInputStream;
import java.nio.channels.FileChannel;

public class GetChannelOfFIS {


	public static void main(String[] args) throws Exception {

		Long slickChunkSize = 10L;
		FileInputStream fis_stm = null;
		FileChannel file_ch = null;
		int count = 0;

		try {
			// Instantiates FileInputStream
			fis_stm = new FileInputStream("C:\\Users\\admin\\Desktop\\新建文本文档.txt");


			while ((count = fis_stm.read()) != -1) {

				// By using read() method is to read
				// a byte from fis_stm
				count = fis_stm.read();

				// Display corresponding bytes value
				byte b = (byte) count;

				// Display value of b
				System.out.println("fis_stm.read(): " + b);

			}

			// By using getChannel() method is to return
			// FileChannel linked with the stream

			file_ch = fis_stm.getChannel();
			System.out.println("fis_stm.getChannel(): " + file_ch);
			System.out.println("fis_stm.getChannel().size(): " + file_ch.size());

			long size = file_ch.size();

			long totalSplit = size / slickChunkSize + (size % slickChunkSize == 0 ? 0 : 1);

			System.out.println(totalSplit);


		} catch (Exception ex) {
			System.out.println(ex.toString());

		} finally {
			// with the help of this block is to
			// free all necessary resources linked
			// with the stream
			if (fis_stm != null) {
				fis_stm.close();
				if (file_ch != null) {
					file_ch.close();
				}
			}
		}
	}
}